import { Moment } from "moment";
import { Reducer } from "react";
import { BudgetItem } from "../../interface/budgetData";
import { ActionProps } from "../type";
import { BudgetListActionEnum } from "./budget-list-type";

export const BudgetListReducer: Reducer<BudgetItem[], ActionProps<BudgetListActionEnum, BudgetItem[] | Moment>> =
    (state: BudgetItem[] = [], action: ActionProps<BudgetListActionEnum, BudgetItem[] | Moment>) =>
    {
        if (action.type === BudgetListActionEnum.SelectBudgetListData)
        {
            if (action.payload)
            {
                state = action.payload as BudgetItem[];
            }
            return state;
        }
        return state;
    };
